#!/usr/bin/env python3
# -*- coding:utf-8 -*-
# @Time: 2019/11/22  22:26
# @Author: 余浪人
# @email: yulangren520@gmail.com
import json
from functools import wraps
from flask import Blueprint, request, current_app, render_template,abort
from flask_themes2 import render_theme_template
from apps.lib.cache_sys import current_theme
from apps.lib.public import redis_

webapp_bp = Blueprint('webapp_bp', __name__)
def render_theme (O0O0O000OO0OO000O ,**OO0O00000O00OOOO0 ):
    OO0000O00000O0OO0 =current_theme ()
    return render_theme_template (OO0000O00000O0OO0 ,f'web_template/{OO0000O00000O0OO0}/templates/{O0O0O000OO0OO000O}',**OO0O00000O00OOOO0 )
def Authority (O00OO0OOO0O0O0000 ):
    @wraps (O00OO0OOO0O0O0000 )
    def OOO00OO0OOO000000 (*O0OO00O0000000O0O ,**OO0000OOOO00O00O0 ):
        O0OOOO00O000000OO =request .remote_addr
        try :
            O0OOO00OOOOO0O0OO =redis_ (2 )
            OO00OO00OO0OOO000 =redis_ (3 )
            OOO0O0O00O00O00OO =O0OOO00OOOOO0O0OO .get (O0OOOO00O000000OO )
        except :return abort (503 ,'The server is not configured correctly,Please configure correctly TL-CMS! If not clear configuration, can contact the developer QQ: 1368419640')
        if OOO0O0O00O00O00OO :
            O0000O0OO0O00OOO0 =json .loads (OOO0O0O00O00O00OO )
            if O0000O0OO0O00OOO0 ['count']==current_app .config ['MAX_NUM']:
                OOO00O000OOO0O00O =OO00OO00OO0OOO000 .set (O0OOOO00O000000OO ,json .dumps (O0OOOO00O000000OO ),current_app .config ['RESTRICT_TIME']*60 )
                if OOO00O000OOO0O00O :O0OOO00OOOOO0O0OO .delete (O0OOOO00O000000OO )
                return render_template ('error_template/error_403.html')
        if OO00OO00OO0OOO000 .get (O0OOOO00O000000OO ):return render_template ('error_template/error_403.html')
        O00OOOOOOOO000O0O =redis_ (4 )
        if O00OOOOOOOO000O0O .hget ('forbid_ip',O0OOOO00O000000OO ):return render_template ('error_template/error_403.html')
        O0O00O000OO000OO0 =O00OO0OOO0O0O0000 (*O0OO00O0000000O0O ,**OO0000OOOO00O00O0 )
        return O0O00O000OO000OO0
    return OOO00OO0OOO000000
from apps .webapp import controller